package org.carota.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @author : AnWen
 * @version :1.0
 * @email : anwen375@qq.com
 * @since : 2023-04-06 9:25
 */
public class RelateUtil {


    public static InputStream getInputStream(String templatePath) throws IOException {

        File file = new File(templatePath);
        if (!file.canRead()){
            if (templatePath.startsWith("file:/") || templatePath.startsWith("http://") || templatePath.startsWith("https://")) {
                return new URL (templatePath).openStream ();
            } else {
                throw new RuntimeException ("初始化输入流异常,暂不支持的模板地址:"+templatePath);
            }
        }
        return new FileInputStream (templatePath);
    }


}
